package ch08.demo.cn.cvs;

import ch08.demo.cn.cvs.entity.SysUser;
import ch08.demo.cn.cvs.service.sysUser.SysUserService;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;


public class SysUserTest {
    private Logger logger=Logger.getLogger(SysUserTest.class);
    @Before
    public void setUp() throws Exception{ }
    @Test
    public void testGetUserList(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext7.xml");
        SysUserService userService= context.getBean(SysUserService.class);
        List<SysUser> userList=new ArrayList<SysUser>();
        SysUser userCondition=new SysUser();
        userCondition.setRealName("赵");
        userCondition.setRoleId(2);
        userList=userService.getList(userCondition);
        for (SysUser userResult:userList){
            logger.debug("testGetUserList account:"
            +userResult.getAccount()+"add realName:"
            +userResult.getRealName()+"add roleId: "
            +userResult.getRoleId()+"and roleName: "
            +userResult.getRoleIdName()+"and address: "
            +userResult.getAddress());
        }
    }
    public void testAddUser() throws ParseException{
        ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext7.xml");
        SysUserService bean = ctx.getBean(SysUserService.class);
        SysUser user=new SysUser();
        user.setRoleId(23);
        user.setAddress("456");
        boolean result=bean.add(user);
        logger.debug("testAdd result:"+result);
    }


}
